package com.yisoo.ubag.product.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.yisoo.ubag.product.entity.DevTokenEntity;
import com.yisoo.ubag.product.service.DevTokenService;
import com.yisoo.common.utils.PageUtils;
import com.yisoo.common.utils.R;



/**
 * 
 *
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-02-06 17:43:43
 */
@RestController
@RequestMapping("product/devtoken")
public class DevTokenController {
    @Autowired
    private DevTokenService devTokenService;

//已经用过的token
    @GetMapping("/used/{cid}")
    public R add(@PathVariable("cid") Long cid){

        return  devTokenService.countUsed(cid);
    }

    /**
     * 保存
     */
    @PostMapping("/add/{num}")
    public R add(@PathVariable("num") Integer num ,@RequestBody DevTokenEntity devToken){

//        System.out.println("&&&&&77"+devToken);



        return  devTokenService.generator(devToken,num);
    }

    /**
     * 修改
     */
    @RequestMapping("/edit/1")
    //@RequiresPermissions("product:devtoken:update")
    public R edit(@RequestBody DevTokenEntity devToken){
        devTokenService.updateById(devToken);
//        System.out.println(devToken);

        return R.ok();
    }




    /**
     * 清空
     */
    @RequestMapping("/clear")
    //@RequiresPermissions("product:devtoken:delete")
    public R clear(@RequestBody String[] runTokens){
        devTokenService.clearByIds(Arrays.asList(runTokens));

        return R.ok();
    }


    /**
     * 列表
     */
    @RequestMapping("/all/{cid}")
    public R all(@RequestParam Map<String, Object> params,@PathVariable("cid") Long cid){
        PageUtils page = devTokenService.queryPageByCid(params,cid);
        return R.ok().put("page", page);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("product:devtoken:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = devTokenService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{runToken}")
    //@RequiresPermissions("product:devtoken:info")
    public R info(@PathVariable("runToken") String runToken){
		DevTokenEntity devToken = devTokenService.getById(runToken);

        return R.ok().put("devToken", devToken);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:devtoken:save")
    public R save(@RequestBody DevTokenEntity devToken){
		devTokenService.save(devToken);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:devtoken:update")
    public R update(@RequestBody DevTokenEntity devToken){
		devTokenService.updateById(devToken);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:devtoken:delete")
    public R delete(@RequestBody String[] runTokens){
		devTokenService.removeByIds(Arrays.asList(runTokens));

        return R.ok();
    }

}
